<template>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="菜单名称">
            <el-input v-model="ruleForm.permissionsName" class="elinput"></el-input>
        </el-form-item>
        <el-form-item label="菜单编码">
            <el-input v-model="ruleForm.element" class="elinput"></el-input>
        </el-form-item>
        <el-form-item label="菜单类型">
            <el-select v-model="ruleForm.type" placeholder="选择类型" class="elinput" @change="typechange">
                <el-option label="菜单" :value="1"></el-option>
                <!-- <el-option label="功能" :value="2"></el-option> -->
            </el-select>
        </el-form-item>
        <el-form-item label="上级菜单">
            <el-input v-model="ruleForm.pidName" class="elinput" disabled></el-input>
        </el-form-item>
        <el-form-item label="排序">
            <el-input v-model="ruleForm.ordernum" class="elinput"></el-input>
        </el-form-item>
        <el-form-item label="启用状态">
            <el-switch v-model="ruleForm.status" active-color="#13ce66" inactive-color="#ff4949" active-value="1"
                inactive-value="0">
            </el-switch>
        </el-form-item>
        <el-form-item label="备注">
            <el-input v-model="ruleForm.rmk" class="elinput"></el-input>
        </el-form-item>
        <el-form-item label="菜单路径">
            <el-input v-model="ruleForm.path" class="elinput"></el-input>
        </el-form-item>
    </el-form>
</template>

<script>
    import PopupTreeInput from "@/components/PopupTreeInput";
    import {
        httpAction,
        getAction
    } from '@/http/axios.js';
    import {
        JVxeMenuTableModelMixin
    } from '@/utils/JVxeMenuTableModelMixin.js'

    export default {
        name: 'MenuChildForm',
        mixins: [JVxeMenuTableModelMixin],
        components: {
            PopupTreeInput
        },
        data() {
            return {
                popupTreeData: [],
                pdata: [],
                defaultProps: {
                    children: 'children',
                    label: 'label'
                },
                loading: true,
                ruleForm: {
                    id: '',
                    permissionsName: '',
                    element: '',
                    status: '1',
                    rmk: '',
                    path: '',
                    icon: '',
                    type: 1,
                    ordernum: '',
                    pidname: '',
                    pid: ''
                },
                rules: {
                    permissionsName: [{
                        required: true,
                        message: '请选择活动区域',
                        trigger: 'change'
                    }]
                },
                editshow: false,
                uploadfileurl: this.$url.baseURL + '/upload/uploadfile',
                showProgress: false,
                progInt: 0,
                fileList: [],
                url: {
                    add: "/sysuser/create",
                    edit: "/sysuser/savePermission"
                }
            }
        },
        props: {
            //表单禁用
            disabled: {
                type: Boolean,
                default: false,
                required: false
            }
        },
        computed: {
            formDisabled() {
                return this.disabled
            },
        },
        created() {},
        methods: {

            typechange(val) {
                this.ruleForm.type = val;
            },
            edit(record) {
                this.visible = true
                this.ruleForm = Object.assign({}, record)
                this.ruleForm.pid = record.id //父级id赋值 pid 创建二级菜单
                this.ruleForm.pidName = record.permissionsName //父级id赋值 pid 创建二级菜单
            },
            /** 确定按钮点击事件 */
            submitForm() {
                this.$refs['ruleForm'].validate((valid) => {
                    if (valid) {
                        let url = this.url.add
                        delete this.ruleForm.updateTime
                        delete this.ruleForm.updateUser
                        delete this.ruleForm.createUser
                        delete this.ruleForm.createusername
                        delete this.ruleForm.createTime
                        delete this.ruleForm.checked
                        delete this.ruleForm.roleid
                        delete this.ruleForm.level
                        delete this.ruleForm.label
                        delete this.ruleForm.id
                        this.confirmLoading = true
                        httpAction(url, this.ruleForm).then(res => {
                            console.log(res);
                            if (res.code === '0') {
                                this.$emit('ok')
                                this.$message.success(res.msg)
                            } else {
                                this.$message.error(res.msg)
                            }
                        }).finally(() => {
                            this.confirmLoading = false
                        })
                    } else {
                        return false;
                    }
                });
            },
        }
    }
</script>

<style scoped>
    /deep/.avatar-uploader .el-upload {
        border: 1px dashed #d9d9d9;
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
    }

    /deep/.avatar-uploader .el-upload:hover {
        border-color: #409EFF;
    }

    /deep/.avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        line-height: 178px;
        text-align: center;
    }

    /deep/.avatar {
        width: 178px;
        height: 178px;
        display: block;
    }

    .edit-cont {
        box-sizing: border-box;
        padding: 20px;
        height: 300px;
        overflow-y: auto;
        border: 1px solid #E4E7ED;
        border-radius: 5px;
    }
</style>
